package com.boesch.electroOffice.utils;

import java.util.Locale;

import javax.faces.context.FacesContext;

import com.liferay.faces.portal.context.LiferayFacesContext;
import com.liferay.faces.util.portal.WebKeys;
import com.liferay.portal.theme.ThemeDisplay;

public class LanguageUtils {

	public static String getCurrentLanguage() {
		return getLocale().getLanguage();
	}

	public static Locale getLocale() {
		FacesContext facesContext = FacesContext.getCurrentInstance();
		ThemeDisplay themeDisplay = (ThemeDisplay) facesContext.getExternalContext().getRequestMap().get(WebKeys.THEME_DISPLAY);
		return themeDisplay.getLocale();
	}

	public static String readI18nText(String key){
		return readI18nText(key, (Object[]) null);
	}

	public static String readI18nText(String key, Object[] arguments){
		LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
		String text = liferayFacesContext.getMessage(LanguageUtils.getLocale(), key, arguments);
		return text;
	}

	@Override
	public String toString() {
		return "LocaleUtils []";
	}
}
